<?php

/**
 * calendrier_planning form.
 *
 * @package    gesp
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class calendrier_planningForm extends Basecalendrier_planningForm {
	public function configure() {
		// redéfinition des widgets
		$this->setWidget('calpln_prj_id', new sfWidgetFormInputHidden());
		unset($this['calpln_date_maj']);
		$this->setWidget('calpln_date', new DatePickerWidget(array('default' => date('d/m/Y'))));
		$this->setWidget('calpln_heure_debut', new sfWidgetFormTime(array('minutes' => array(0 => '00', 15 => '15', 30 => '30', 45 => '45'), 'default' => '00:00')));
		$this->setWidget('calpln_heure_fin', new sfWidgetFormTime(array('minutes' => array('00', '15', '30', '45'))));

		$this->setWidget('calpln_freq', new sfWidgetFormSelect(array('choices' => Calendrier_PlanningTable::getFrequences(), 'default' => 'S')));
		if (!$this->getObject()->isNew()) {
			switch ($this->getObject()->getCalplnFreq()) {
			case 'M':
				$this->setWidget('calpln_jour', new sfWidgetFormSelect(array('choices' => Calendrier_PlanningTable::getJoursMois(), 'default' => 1)));
				break;
			case 'S':
				$this->setWidget('calpln_jour', new sfWidgetFormSelect(array('choices' => Calendrier_PlanningTable::getJoursSemaine(), 'default' => 1)));
				break;
			}
		} else {
			$this->setWidget('calpln_jour', new sfWidgetFormSelect(array('choices' => Calendrier_PlanningTable::getJoursSemaine(), 'default' => 1)));
		}

		// modification des libellés
		$this->widgetSchema->setLabels(array(
			'calpln_date' => 'Date',
			'calpln_heure_debut' => 'Heure de début',
			'calpln_heure_fin' => 'Heure de fin',
			'calpln_libelle' => 'Libellé',
			'calpln_description' => 'Description',
			'calpln_freq' => 'Fréquence',
			'calpln_jour' => 'Jour',
			'calpln_actif' => 'Actif',
		));

		// redéfinition des validateurs
		$this->validatorSchema['calpln_libelle']->setOption('required', true);
		$this->setValidator(
			'calpln_date',
			new ValidatorDate(array(
				'required' => true,
				'date_format' => '/^(?P<day>\d+)\/(?P<month>\d+)(\/(?P<year>\d+))?/',
				),
				array(
				'bad_format' => "format de date invalide : dd/mm[/yyyy]",
				)
			)
		);
	}


}
